home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4600 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.2 KB

  1. Path: dialup-123.austin.io.com!user
  2. From: hamilton@shokwave.com (Jim Hamilton)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: for loop question
  5. Date: Tue, 30 Jan 1996 23:38:29 -0600
  6. Organization: Disorganized
  7. Message-ID: <hamilton-3001962338300001@dialup-123.austin.io.com>
  8. References: <4emqf8$470@opal.southwind.net>
  9. NNTP-Posting-Host: dialup-123.austin.io.com
  10. X-Newsreader: Yet Another NewsWatcher 2.0.5b5
  11.  
  12. In article <4emqf8$470@opal.southwind.net>, kurtg@southwind.net (Kurt
  13. Graber) wrote:
  14.  
  15. >I am currently learning c++ so maybe you gurus can answer this
  16. >also I am using borland turbo c++ 3.0
  17. >I can't get the following code to give me any output.
  18. >
  19. >#include <iostream.h>
  20. >
  21. >void main (void)
  22. >{
  23. >   int a;
  24. >   for(a = 0;a == 10;a++)
  25. >   {
  26. >    cout << "anything";
  27. >   }
  28. >}
  29.  
  30. The loop will exit on the first iteration because a != 10
  31. Remember that 
  32.  
  33. for(e1;e2;e3) {
  34.    some_stuff
  35. }
  36.  
  37. is equivalent to 
  38.  
  39. e1;
  40. while(e2) {
  41.    some_stuff
  42.    e3;
  43. }
  44.  
  45. As you wrote:
  46.  
  47. a = 0;
  48. while (a == 10) {...}   // will never execute
  49.  
  50. >
  51. >///If I change the loop to     for(a=0;a<=10;a++)
  52. >   the program will work fine.   
  53. >   why?????????
  54. >    thanks 
  55. >         kurt
  56.  
  57. -- 
  58. JFH
  59.  
  60. [This .sig intentionally left blank.]
  61.